"""首页的各项数据测试"""

import requests
from common.config_log import Logger
logger = Logger().log()

class HomePage():
    headers = {
        "Cookie":"TrainingPlatform-sid=s%3AndD2yduLWwumhExLSMjsIBkBPL8dFwQD.lDRg8fBdx8ZyIXs2MQ3Zatqq9Xl3KcetfbWjkhhnv%2BM; local-state={%22_id%22:%225f02f2349fd8b6fa72e727cf%22%2C%22username%22:%22admin%22%2C%22email%22:%22admin@forensix.cn%22%2C%22roles%22:[%22admin%22]%2C%22avatar%22:%22http://account-test.forensix.cn/avatars/avatar.5a4e0bc20de70d51abff9cc8.1142.png%22%2C%22isReset%22:false%2C%22isModifyPersonal%22:true}; XSRF-TOKEN=o1Yddi58-hs1q_4dikGLpWZWJ-fxDvH1P_YE"
    }

    url = "http://172.16.60.14/statistics"

    """首页题库总数"""
    total_json = requests.get(url, headers=headers).json()




    # 已发布 实训套题《中级》模块占比
    #
    #

    # 已发布 实训套题《高级》模块占比
    #
    #

    # 已发布 实训套题《真题》模块占比
    #

    """实训题库总数"""
    def train_total(self):
        training_total_url = "http://172.16.60.14/testPapers?skip=0&limit=10&orderField=createAt&descend=1&forTraining=true"
        training_total_response = requests.get(training_total_url, headers=self.headers).json()
        training_total = self.total_json['total'][1]['total']
        actual_training_total = training_total_response['total']

        actual_training_page = actual_training_total // 10
        end_page_num = actual_training_total % 10

        end_page_url = "http://172.16.60.14/testPapers?skip={}&limit=10&orderField=createAt&descend=1&fortraining=true".format(
            actual_training_page * 10)
        actual_end_page_num = len(requests.get(end_page_url, headers=self.headers).json()['testPapers'])

        logger.info("首页实训题库总数[{}]".format(training_total))
        logger.info("实训题库页面题库总数[{}]".format(actual_training_total))
        return training_total, actual_training_total

    """竞赛题库总数"""
    def compatation_total(self):
        competation_total = self.total_json['total'][0]['total']

        competation_total_url = "http://172.16.60.14/testPapers?skip=0&limit=10&orderField=createAt&descend=1&forCompetition=true"
        competation_total_response = requests.get(competation_total_url, headers=self.headers).json()
        actual_competation_total = competation_total_response['total']
        actual_competation_page = actual_competation_total // 10
        com_end_page_num = actual_competation_total % 10

        com_end_page_url = "http://172.16.60.14/testPapers?skip={}&limit=10&orderField=createAt&descend=1&forCompetition=true".format(actual_competation_page*10)
        com_actual_end_page_num = len(requests.get(com_end_page_url, headers=self.headers).json()['testPapers'])

        logger.info("首页竞赛题库总数[{}]".format(competation_total))
        logger.info("竞赛题库页面题库总数[{}]".format(actual_competation_total))
        return competation_total, actual_competation_total


    # 已发布 实训套题《初级》模块占比
    def publish_senior(self):
        url = "http://172.16.60.14/statistics/block?status=published"
        actual_url = "http://172.16.60.14/testPapers?skip=0&limit=10&orderField=createAt&descend=1&level=1&status=published&forTraining=true"

        response = requests.get(url, headers=self.headers).json()
        actual_response = requests.get(actual_url, headers = self.headers).json()

        primary = response[0]['total']
        medium = response[1]['total']
        senior = response[2]['total']
        forcompetation = response[3]['total']
    #

    # 未发布 实训套题《初级》模块占比
    #
    #

    # 未发布 实训套题《中级》模块占比
    #
    #

    # 未发布 实训套题《高级》模块占比
    #
    #

    # 未发布 实训套题《真题》模块占比
    #
    #

    # 已发布 实训套题《初级》模块占比
    #
    #

    # 已发布 实训套题《中级》模块占比
    #
    #

    # 已发布 实训套题《高级》模块占比
    #
    #
    #
    # 实训 单选题
    #
    #
    #
    # 实训 多选题
    #
    #
    #
    # 实训 填空题
    #
    #
    #
    # 竞赛 单选题
    #
    #
    #
    # 竞赛 多选题
    #
    #
    #
    # 竞赛 填空题
    #
    #
    #
    # 竞赛 主观题
    #
    #
    #
    # 用户数
